<?xml version="1.0" encoding="UTF-8" ?>
 
<xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns="http://www.w3.org/1999/xhtml">
    <xsl:output method="xml" indent="no"
        doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

<xsl:include href="../../../templates/root.xsl"/>
<xsl:include href="../../../templates/date_selector.xsl"/>
<xsl:include href="report_selector.xsl"/>

<xsl:template match="*"/>

<xsl:template match="report_name">
    <xsl:call-template name="reportSelector"/>
    <xsl:call-template name="dateSelector"/>
    <h1><xsl:value-of select="."/></h1>
</xsl:template>

<xsl:template match="report_data">
    <script type="text/javascript">
        <xsl:comment>
        <![CDATA[
        function openPopup(a)
        {
            var win = window.open();
            win.document.location.href=a.href;
            return false;
        }
        ]]> 
        </xsl:comment>
    </script>
    <table class="reportTable" id="reportTable">
        <tr>
            <th>Ссылка</th>
            <th>Просмотров</th>
        </tr>
        <xsl:apply-templates select="row"/>
    </table>
</xsl:template>

<xsl:template match="row">
        <tr>
            <td style="text-align: left;"><a href="{@url}" target="_blank" onclick="return openPopup(this);" class="external"><xsl:value-of select="@urlHuman"/></a></td>
            <td><a href="report.php?module=popularity&amp;report=hits&amp;date1={/root/date1}&amp;date2={/root/date2}&amp;by=link&amp;dirs={@dirId}&amp;file={@fileId}&amp;query={@queryId}" target="_blank"><xsl:value-of select="@summ"/></a></td>
        </tr>
</xsl:template>


<xsl:template match="report_data_more">
    <div align="center"><input type="button" onclick="showMore();" id="showMoreButton" value="Показать ещё"/></div>
    <input type="hidden" id="showMoreDate1" value="{/root/date1}"/>
    <input type="hidden" id="showMoreDate2" value="{/root/date2}"/>
    <input type="hidden" id="showMoreDirs" value="{@dirs}"/>
    <input type="hidden" id="showMoreStart" value="{@start}"/>
    <input type="hidden" id="showMoreCount" value="{@count}"/>
    <script src="design/append_table.js" type="text/javascript"/>
    <script src="design/httprequest.js" type="text/javascript"/>
    <script type="text/javascript">
        <xsl:comment>
        <![CDATA[
        function onData(data)
        {
            from = data.getElementsByTagName('table');
            to = document.getElementById('reportTable');
            if (from.length > 0 && to) {
                var count = appendTable(from.item(0), to);
                document.getElementById('showMoreStart').value = parseInt(document.getElementById('showMoreStart').value) + count;
                if (count >= document.getElementById('showMoreCount').value)
                    document.getElementById('showMoreButton').disabled = false;
                else
                    document.getElementById('showMoreButton').value = 'Всё закончилось.';
            }
        }
        function onError(text)
        {
            document.getElementById('showMoreButton').disabled = false;
            alert(text);
        }
        function showMore(){
            document.getElementById('showMoreButton').disabled = true;
            var params = 'module=popularity&report=links_more';
            params += '&date1='+document.getElementById('showMoreDate1').value;
            params += '&date2='+document.getElementById('showMoreDate2').value;
            params += '&dirs='+document.getElementById('showMoreDirs').value;
            params += '&start='+document.getElementById('showMoreStart').value;
            params += '&count='+document.getElementById('showMoreCount').value;
            httpRequest('report.php', params, onData, onError, {'asHTML': true});
        }
        ]]> 
        </xsl:comment>
    </script>
</xsl:template>

</xsl:stylesheet>